from utils.sendmethod import Send_Method
from utils.operationdata import OperationData


class UmsMemberController(Send_Method):
    mall_ip = "http://47.108.206.100:8085"

    # 获取验证码接口
    def getAuthCode(self, telephone):
        url = self.mall_ip + '/sso/getAuthCode'
        payload = {"telephone": telephone}
        return self.send_Method(method='get', url=url, params=payload)

    # 注册接口
    def register(self, autoCode, username, telephone, password):
        url = self.mall_ip + '/sso/register'
        print(autoCode, password, telephone, username)
        if autoCode == '':
            payload = {'authCode': autoCode, "password": password, "telephone": telephone, "username": username}
        else:
            payload = {'authCode': eval(autoCode), "password": password, "telephone": telephone, "username": username}
        return self.send_Method(method='post', url=url, data=payload)

    # 会员登录
    def sso_login(self, username='admin', password='123456'):
        url = self.mall_ip + '/sso/login'
        payload = {"password": password, "username": username}
        response = self.send_Method(method='post', url=url, data=payload)
        print(response.json())
        tokenHead = response.json()['data']['tokenHead']
        token = response.json()['data']['token']
        headers = tokenHead + token
        return headers


if __name__ == '__main__':
    um = UmsMemberController()
    print(um.sso_login())
